﻿using DotNetExtensions.Core.IOC;
using DotNetExtensions.Core.MVC;
using DotNetExtensions.Core.WebApi.Jwt;
using Microsoft.Extensions.Caching.Memory;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace CoreWebSimple.JWT
{
    [Inject]
    public class TestJwtValidateService : JwtValidateService<UserModel>
    {
        private readonly IMemoryCache memoryCache;
        public TestJwtValidateService(IMemoryCache memoryCache)
        {
            this.memoryCache = memoryCache;
        }
        public override bool Validate(string token, JwtParameters parameters, out UserModel user, out string refreshKey)
        {
            user = new UserModel()
            {
                Id = 1,
                Name = "Test"
            };
            string sid = parameters.First(x => x.Name == JwtParameters.Sid).Value;
            memoryCache.Set(sid, user);
            refreshKey = Guid.NewGuid().ToString();
            return true;
        }
    }
}
